#!C:/strawberry/perl/bin/perl.exe


use strict;
use warnings;

use CGI;
use RPC::XML;
use RPC::XML::Client;
#use XML::Dumper;
use Data::Dumper;
use XML::Simple;
use XML::eXistDB::RPC;
use XML::Compile::RPC::Client;

# read the CGI params
my $cgi = CGI->new;
#my $email='email@email.com';
my $email = $cgi->param("email");
my $eXist = XML::eXistDB::RPC->new(destination=>"http://localhost:8080/exist/xmlrpc/", repository=>"/db", user=>"admin", password=>"eaf2julian" ) ;

my $xquery = 'doc("/placeanddate/usuarios.xml")/usuarios/usuario[email/text() eq "'.$email.'"]' ;
my ($rc1, $set) = $eXist->executeQuery($xquery) ;
my ($rc2, $count) = $eXist->numberOfResults($set) ;
my ($rc3, @data) = $eXist->retrieveResults($set) ;
$eXist->releaseResultSet($set) ;

my $json=qq{{"nombre" : "$data[0]{'usuario'}{'nombre'}", "apellidos" : "$data[0]{'usuario'}{'apellidos'}", "email" : "$data[0]{'usuario'}{'email'}"}};
# return JSON string
print $cgi->header(-type => "application/json", -charset => "utf-8");
print $json;